define([

], function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        var ResultOptions = [
          { key: 'Y', value: '同意' },
          { key: 'N', value: '否决' },
          { key: 'G', value: '弃权' }
        ];
        return {
          urls: {
            index: backend.workflowService + '/api/metting/myOp',
            vote: backend.workflowService + '/api/metting/op'
          },
          tableColumns: [
            { label: '流程实例号', prop: 'instanceId', resizable: true},
            { label: '业务流水号', prop: 'bizId', resizable: true, hidden: false},
            { label: '会议主题', prop: 'mettingSub', resizable: true},
            { label: '开始时间', prop: 'startTime', resizable: true},
            { label: '结束时间', prop: 'endTime', resizable: true},
            { label: '会议年份', prop: 'mettingYear', resizable: true},
            { label: '会议期数', prop: 'mettingNo', resizable: true},
            { label: '意见', prop: 'mettingComment', resizable: true},
            {
              label: '结论',
              prop: 'mettingSts',
              resizable: true,
              template: function () {
                return '<template scope="scope">\
                <yu-tag type="success" v-if="scope.row.mettingSts==\'Y\'">同意</yu-tag>\
                <yu-tag type="danger" v-if="scope.row.mettingSts==\'N\'">否决</yu-tag>\
                <yu-tag type="warning" v-if="scope.row.mettingSts==\'G\'">弃权</yu-tag>\
                <yu-tag type="gray" v-if="scope.row.mettingSts==null">未投票</yu-tag>\
                </template>';
              }
            },
            { label: '参会人', prop: 'userId', resizable: true},
            { label: '参会人姓名', prop: 'userName', resizable: true},
            {
              label: '操作',
              width: 100,
              fixed: 'right',
              template: function () {
                return '<template scope="scope">\
						                    <el-button size="small" type="text" @click="$emit(\'custom-row-op\',scope,\'vote\')">投票</el-button>\
						                    </template>';
              }
            }
          ],
          updateFields: [
            {
              columnCount: 2,
              fields: [
                { label: '流程实例号', field: 'instanceId', type: 'input', disabled: true, rules: [{ required: true, message: '必填项' }] },
                { label: '业务流水号', field: 'bizId', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] },
                { label: '参会人', field: 'userId', type: 'input', disabled: true, rules: [{ required: true, message: '必填项' }] },
                { label: '参会人姓名', field: 'userName', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] },
                { label: '结束时间', field: 'endTime', type: 'input', hidden: true, rules: [{ required: false, message: '必填项' }] },
                { label: '会议主题', field: 'mettingSub', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] },
                { label: '开始时间', field: 'startTime', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] },
                { label: '会议年份', field: 'mettingYear', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] },
                { label: '会议期数', field: 'mettingNo', type: 'input', disabled: true, rules: [{ required: false, message: '必填项' }] }

              ]
            },
            {
              columnCount: 1,
              fields: [
                { field: 'mettingSts', label: '结论', type: 'select', options: ResultOptions, rules: [{ required: true, message: '必填项', trigger: 'blur' }] },
                { label: '意见', field: 'mettingComment', type: 'textarea', rules: [{ required: true, message: '必填项', trigger: 'blur' }] }
              ]
            }
          ],
          baseParams: {
            condition: { userId: yufp.session.userCode }
          },
          height: yufp.frame.size().height - 103,
          dialogVisible: false,
          viewTitle: '投票',
          formdata: {}
        };
      },
      methods: {
        customRowOp: function (scope, op) { // 表格操作按钮事件
          var _self = this;
          // 当前行号：scope.$index
          // 当前行数据：scope.row
          // 当前列对象：scope.column
          // this.$alert('你现在正在操作：' + op + '当前行ID值为：' + scope.row.flowId, '提示');
          if (op == 'vote') {
            if (scope.row.mettingSts != null) {
              _self.$message({ message: '投票已结束!', type: 'warning' });
            } else {
              _self.$nextTick(function () {
                _self.voteFn();
              });
            }
          }
        },
        voteFn: function () {
          if (this.$refs.reftable.selections.length !== 1) {
            this.$message({ message: '请选择至少一条数据!', type: 'warning' });
            return false;
          }
          var obj = this.$refs.reftable.selections[0];
          this.dialogVisible = true;
          this.$nextTick(function () {
            var reform = this.$refs.reform;
            reform.formModel = obj;
          });
          this.dialogVisible = true;
        },
        nwfVoteFn: function () {
          var _self = this;
          var param = {};
          var reform = _self.$refs.reform;
          reform.validate(function (valid) {
            if (valid) {
              yufp.extend(param, reform.formModel);
              yufp.service.request({
                url: _self.urls.vote,
                data: param,
                method: 'POST',
                callback: function (code, message, response) {
                  if (response.data) {
                    _self.$message({ message: '投票成功', type: 'success' });
                    _self.$refs.reform.resetFields();
                    _self.dialogVisible = false;
                    _self.$refs.reftable.remoteData();
                  }
                }
              });
            } else {
              _self.$message({ message: '请检查输入项是否合法', type: 'warning' });
              return false;
            }
          });
        },
        cancel: function () {
          this.dialogVisible = false;
        }
      }
    });
  };
});

